In modern computer systems, a typical central processing unit (CPU) performs an event processing that constantly overlaps the CPUS's execution of computation functions with the execution of input/output (I/O) functions. Event-based programs help the CPU s run multiple tasks by using a computation structure that features a main control loop (“main loop”) that allows for breaks, running a collection of callback functions whenever an “event,” which is a predefined kind of occurrence outside the program of the main loop, occurs. These callback functions are associated with event types. These event types may include, but are not limited to: user actions (such as keyboard and mouse actions), completion of an internal I/O function, timed hardware events, and arrival of data from another computer. Complete processing of a particular event may also involve a sequence of callbacks that are triggered by one or more successive events.
Event-driven programs use a library of events that contains an association table correlating specific events with specific callbacks to support the CPU's management of events as they occur. The callback functions may be machine instructions directing the CPU or other hardware components to take specific actions. The library may also contain the main loop, which alternates the state of operation between waiting for an event to occur and calling the associated callback. The main loop may be seen as comprising two distinct sections: an event selection section that checks for the occurrence of an event, and an event-handling section that may be a subroutine or method corresponding to the event that handles the event through a callback.
Microcontrollers, which are usually designed for specific, dedicated applications, may also be implemented to handle events. Microcontrollers, though having a processing unit, also contain other components, such as timers, serial I/O, program memory, to handle specific functions. As a result, microcontroller design emphasizes simplicity to handle its dedicated function. A microcontroller may also supplement the function of a CPU, processing certain instructions in lieu of the CPU. Given a series of instructions, a microcontroller may be designed to handle events in a more complex manner. Microcontrollers may be designed to monitor and handle multiple events that occur from multiple inputs or components.
Previous implementations for event-driven programming have generally related both to software and hardware implementations in the CPU. These implementations use the main control loop, i.e., the CPU, to monitor for events. Among other effects, this meant that, in some instances, such as an idling “waiting for interrupt,” the CPU could not stop processing while waiting for an event to occur. Instead, the CPU ran the main control loop, constantly executing instructions in order to stay in the loop, which was time consuming and drained system resources simply while waiting for another event to occur. For some events like I/O operations from infrequently-used peripherals, such as, for example, faxes, scanners, and printers, the persistent monitoring resulted in great waste of energy and system resources.
In view of the foregoing, it would be desirable to more efficiently and reliably monitor events that trigger microprocessor action. More specifically, it would also be desirable to design a microcontroller to handle complex events, while maintaining a simple microcontroller design, maintaining low power consumption by a microprocessor within the microcontroller, and enabling the monitoring various devices for specific events to occur.